﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ChinaGS.Lian.ModuleRemoting;

public partial class pay_express_fill_utilities_nc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SysCommon.checkUserLogin();
        if (!IsPostBack)
        {
            String SumMoney = Request["HidSumMoney"];
            String CusAddress = Request["HidCusAddress"];
            String CusName = Request["HidCusName"];
            String CusNo = Request["HidCusNo"];
            String DefCode = Request["HidDefCode"];

            if (Request["HidSumMoney"] != null)
            {
                LabSumMoney.Text = SumMoney;
                LabCusAddress.Text = CusAddress;
                LabCusName.Text = CusName;
                LabCusNo.Text = CusNo;

                HidSumMoney.Value = SumMoney;
                HidCusAddress.Value = CusAddress;
                HidCusName.Value = CusName;
                HidCusNo.Value = CusNo;
                HidDefCode.Value = DefCode;
               
                PanPay.Visible = true;
            }
            else
            {
                PanPay.Visible = false;
                this.LabMessage.Text = "操作失败，请重试！";
            }
        }
    }
    protected void NextStep_Click(object sender, EventArgs e)
    {        
         //充值前操作            
        int user_paid_id = DataBaseOperate_SQLServer.execPPaidAtonce(Session["user_id"].ToString(), "7".ToString(), HidCusNo.Value, 
                TexPayMoney.Text, TexPayMoney.Text, "0".ToString(), "0".ToString(), "0".ToString(), System.DateTime.Now.ToString(), "none".ToString());

        if (user_paid_id < 0)
        {
            LabMessage.Text = "操作失败！原因是：" + RemotingClass.alertExecErroeResult(user_paid_id).ToString() + "，请重试";
            PanPay.Visible = false;
        }
        else {
            UtilitiesNoCardPackage uncp = RemotingClass.utilitiesNoCardPayMoney(HidDefCode.Value, HidCusNo.Value, System.Convert.ToDouble(TexPayMoney.Text));

            //测试使用
            /*UtilitiesNoCardPackage uncp = new UtilitiesNoCardPackage();
            uncp.Status = true;
            uncp.SerialNo = "1234567890";
            uncp.Message = "success";
            uncp.StatusNo = "00";

            uncp.CusNo = HidCusNo.Value;
            uncp.CusName = "Denveryee";
            uncp.CusAddress = "qd";
            uncp.SumMoney = 1000;

            NocardPeriod np1 = new NocardPeriod();
            np1.Period = "one";
            np1.RecviMoney = 900;
            np1.DefCode = "12345678901234567890";

            NocardPeriod np2 = new NocardPeriod();
            np2.Period = "two";
            np2.RecviMoney = 100;
            np2.DefCode = "12345678901234567890";

            NocardPeriod[] nps = new NocardPeriod[2] { np1, np2 };
            uncp.Periods = nps;*/

            if (uncp.Status)
            {
                //充值成功操作                
                DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), uncp.SerialNo,
                    uncp.CusNo, uncp.Message, "1".ToString(), SysCommon.getClientIP(), "0".ToString());

                Response.Redirect("paysuccess_utilities_nc.aspx?"
                                                 + "HidSumMoney=" + uncp.SumMoney
                                                + "&HidCusAddress=" + uncp.CusAddress
                                                + "&HidCusName=" + uncp.CusName
                                                + "&HidCusNo=" + uncp.CusNo
                                                + "&HidPayMoney=" + TexPayMoney.Text);
            }
            else
            {
                //充值失败操作                
                DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), uncp.SerialNo,
                    uncp.CusNo, uncp.Message, "2".ToString(), SysCommon.getClientIP(), "0".ToString());

                LabMessage.Text = "操作失败！原因是：" + uncp.Message + "，请稍后重试";
                PanPay.Visible = false;
            }
        }
        
    }
}
